//package com.jomoo.css.common.util.service;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.jomoo.css.common.util.security.AuthenticationUser;
//import com.jomoo.css.common.util.errors.BadRequestAlertException;
//import com.jomoo.css.common.util.helper.CachedBeanCopier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Primary;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Service;
//import com.jomoo.css.common.util.mapper.SYSUSERMapper;
//import com.jomoo.css.common.util.domain.SYSUSER;
//import org.springframework.util.DigestUtils;
//import org.springframework.util.StringUtils;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
//import org.springframework.security.core.authority.AuthorityUtils;
//
///**
// * 实体[SYSUSER] 服务对象接口实现
// */
//@Service("SYSUSERService")
//@ConditionalOnExpression("(!${sys.enablePermissionValid:false})&&'${sys.auth.service:SYSUAAUserService}'.equals('SYSUSERService')")
//public class SYSUSERServiceImpl extends ServiceImpl<SYSUSERMapper, SYSUSER> implements SYSUSERService,AuthenticationUserService{
//
//	@Value("${sys.auth.pwencrymode:0}")
//	private int pwencrymode;
//
//	@Override
//	public AuthenticationUser loadUserByUsername(String username) {
//		if(StringUtils.isEmpty(username)) {
//			throw new UsernameNotFoundException("用户名为空");
//		}
//		QueryWrapper<SYSUSER> conds = new QueryWrapper<SYSUSER>();
//		String[] data = username.split("[|]");
//		String loginname = "";
//		String domains = "";
//		if(data.length>0) {
//			loginname = data[0].trim();
//		}
//		if(data.length>1) {
//			domains = data[1].trim();
//		}
//		if(!StringUtils.isEmpty(loginname)) {
//			conds.eq("loginname",loginname);
//		}
//		if(!StringUtils.isEmpty(domains)) {
//			conds.eq("domains",domains);
//		}
//		SYSUSER user = this.getOne(conds);
//		if (user == null) {
//			throw new UsernameNotFoundException("用户" + username + "未找到");
//		}
//		else {
//			user.setUsername(username);
//			return createUserDetails(user);
//		}
//	}
//
//	@Override
//	public AuthenticationUser loadUserByLogin(String username, String password){
//		AuthenticationUser authuserdetail = loadUserByUsername(username);
//		if(pwencrymode == 1){
//			password = DigestUtils.md5DigestAsHex(password.getBytes());
//		}
//		else if(pwencrymode == 2){
//			password = DigestUtils.md5DigestAsHex(String.format("%1$s||%2$s", username, password).getBytes());
//		}
//		if(!authuserdetail.getPassword().equals(password)) {
//			throw new BadRequestAlertException("用户名密码错误","SYSUSER",username);
//		}
//		return authuserdetail;
//	}
//
//
//	public void resetByUsername(String username) {
//
//	}
//
//	public  AuthenticationUser createUserDetails(SYSUSER user) {
//		AuthenticationUser userdatail = new AuthenticationUser();
//		CachedBeanCopier.copy(user,userdatail);
//    	if(userdatail.getSuperuser() == 1){
//    		userdatail.setAuthorities(AuthorityUtils.createAuthorityList("ROLE_SUPERADMIN"));
//    	}
//		return userdatail;
//	}
//}